//! Access kinds of resource
var GeoFeatureModel = require('./GeoFeatureModel');
var TagInfoModel = require('./TagInfoModel');
var ObjectId = require('mongodb').ObjectID;
var uuid = require('uuid');

function GeoFeature(){
    this._id = new ObjectId();
    this.MetaID = uuid.v4();
    this.FeatureID = uuid.v1();
    this.ID = 3000000;
    this.Event = null;
    this.Place = null;
    this.Thing = null;
    this.Time = null;
    this.Person = null;
    this.Phenomenon = null;
    this.Scene = null;
    return this;
}

GeoFeature.prototype.ConfigureEvent = function(TagType, TagID, Value){
    this.Event = {
        TagType : TagType,
        TagID : TagID,
        Value : Value
    }
}

GeoFeature.prototype.ConfigurePlace = function(TagType, TagID, Value){
    this.Place = {
        TagType : TagType,
        TagID : TagID,
        Value : Value
    }
}

GeoFeature.prototype.ConfigureThing = function(TagType, TagID, Value){
    this.Thing = {
        TagType : TagType,
        TagID : TagID,
        Value : Value
    }
}

GeoFeature.prototype.ConfigureTime = function(TagType, TagID, Value){
    this.Time = {
        TagType : TagType,
        TagID : TagID,
        Value : Value
    }
}

GeoFeature.prototype.ConfigurePerson = function(TagType, TagID, Value){
    this.Person = {
        TagType : TagType,
        TagID : TagID,
        Value : Value
    }
}

GeoFeature.prototype.ConfigurePhenomenon = function(TagType, TagID, Value){
    this.Phenomenon = {
        TagType : TagType,
        TagID : TagID,
        Value : Value
    }
}

GeoFeature.prototype.ConfigureScene = function(TagType, TagID, Value){
    this.Scene = {
        TagType : TagType,
        TagID : TagID,
        Value : Value
    }
}

function ResourceAccess(){}

ResourceAccess.CreateGeoFeature = function(){
    return new GeoFeature();
};

ResourceAccess.BindTagCollection = function(collection){
    TagInfoModel.BindCollection(collection);
};

ResourceAccess.GetAllTagDocument = function(callback){
    TagInfoModel.getAll(function(err, data){
        return callback(err, data);
    });
}

ResourceAccess.InsertGeoFeature = function(geoFeature, callback){
    var gFeature = new GeoFeatureModel(geoFeature);
    GeoFeatureModel.save(gFeature, function(err, data){
        if(err){
            return callback(err);
        }
        else{
            return callback(null, true);
        }
    });
};

module.exports = ResourceAccess;